package pl.ydp.components.mathcell.mathcell.preprocessing.multicharacter
{
	/** 
	 * Provedes the functionality for the analysis of multiple
	 * characters in a cell.
	 */
	public class MultiCharacterContainer5
	{
		public function MultiCharacterContainer5(penPoints:Array, maxCharactersCount:Number, cellWidth:Number, cellHeight:Number, allowFractions:Boolean){
			
			charactersPoints = MultiCharacterSeparator.separate(penPoints, maxCharactersCount, 
				cellWidth, cellHeight, MultiCharactersLayout.HORIZONTAL);
				
			fractionsCharactersPoints = new Array;
				
			var tmpFractionCharactersPoints:Array;
			var tmpNumeratorCharactersPoints:Array;
			var tmpDenominatorCharactersPoints:Array;
				
			for (var chp:Number = 0 ; chp < charactersPoints.length ; chp ++){
				
				fractionsCharactersPoints.push(new Array);
				
				if (allowFractions){				
					tmpFractionCharactersPoints = MultiCharacterSeparator.separate(charactersPoints[chp], 3, 
						cellWidth, cellHeight, MultiCharactersLayout.VERTICAL);
						
					if (tmpFractionCharactersPoints.length == 3){
						tmpNumeratorCharactersPoints = MultiCharacterSeparator.separate(tmpFractionCharactersPoints[0], 3, 
							cellWidth, cellHeight, MultiCharactersLayout.HORIZONTAL);
						tmpDenominatorCharactersPoints = MultiCharacterSeparator.separate(tmpFractionCharactersPoints[2], 3, 
							cellWidth, cellHeight, MultiCharactersLayout.HORIZONTAL);
							
						fractionsCharactersPoints[chp].push(tmpNumeratorCharactersPoints);
						fractionsCharactersPoints[chp].push(tmpDenominatorCharactersPoints);
					} 
				}
			}
			
		}
		
		private var charactersPoints:Array;
		private var fractionsCharactersPoints:Array;
		
		public function get charactersCount():Number{
			return charactersPoints.length;
		}
		
		public function getCharacterPointsAt(index:Number):Array{
			if (charactersPoints == null  ||  index >= charactersPoints.length)
				return new Array;
				
			return charactersPoints[index];
		}
		
		public function isFractionAt(index:Number):Boolean{
			if (fractionsCharactersPoints == null  ||  index >= fractionsCharactersPoints.length)
				return false;
				
			return (fractionsCharactersPoints[index].length == 2);
		}
		
		public function getFractionNumeratorCharactersPointsAt(index:Number):Array{
			if (fractionsCharactersPoints == null  ||  index >= fractionsCharactersPoints.length  ||  !isFractionAt(index))
				return null;
				
			return fractionsCharactersPoints[index][0];
		}

		public function getFractionDenominatorCharactersPointsAt(index:Number):Array{
			if (fractionsCharactersPoints == null  ||  index >= fractionsCharactersPoints.length  ||  !isFractionAt(index))
				return null;
				
			return fractionsCharactersPoints[index][1];
		}
		
		public function isDotsAt(index:Number):Boolean{
			var currStroke:Array;
			
			for each (currStroke in charactersPoints[index]){
				if (!MultiCharacterSeparator.isDot(currStroke)){
					return false;
				}
			}
			return true;
		}

	}
}